package com.fjc.jms;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;


/**
 * Created by fjc on 2019/2/21.
 */
@Component
public class SmsProcessor {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Autowired
    private SmsSender smsSender;

    public void sendSmsToQueue(Destination destination, String message){
        jmsMessagingTemplate.convertAndSend(destination,message);
    }

    @JmsListener(destination = "sms.queue")
    public void doSendSmsMessage(String data)throws Exception{
        JSONObject jsonObject = JSON.parseObject(data);
        smsSender.sendSms(jsonObject.getString("mobile"),jsonObject.getString("code"));
    }
}
